package com.movecar.listener;

import BLLocationCallbacker.BLLocationCallbacker;
import BLLocationCallbacker.BLLocationListener;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.amap.api.location.core.GeoPoint;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.movecar.application.MainApplication;

public class BaseLocationActivity extends FragmentActivity implements BLLocationCallbacker {
	public LocationClient mLocationClient;
	private BDLocationListener mLocationListener;

	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		(mLocationClient = ((MainApplication) getApplication())
				.getLocationClient())
				.registerLocationListener(mLocationListener = new BLLocationListener(this));
	}

	@Override
	protected void onPause() {
		if (mLocationClient.isStarted()) {
			mLocationClient.stop();
		}
		super.onPause();
	}

	@Override
	protected void onDestroy() {
		mLocationClient.unRegisterLocationListener(mLocationListener);
		super.onDestroy();
	}

	@Override
	public void onLocation(final GeoPoint location, final String city) {
		mLocationClient.stop();
	}

	/**
	 * 请求定位当前位置。
	 * 
	 * @since 1.0.1
	 */
	public void requestLocation() {
		if (!mLocationClient.isStarted()) {
			mLocationClient.start();
		} else {
			mLocationClient.requestLocation();
		}
	}
}
